package summary;

/**
 * @Author: 海琳琦
 * @Date: 2022/3/6 20:19
 * https://leetcode-cn.com/problems/valid-perfect-square/
 */
public class Title367 {

    public boolean isPerfectSquare(int num) {
        int left = 0, right = num / 2 + 1;
        while (left <= right) {
            int middle = (left + right) / 2;
            if ((long) middle * middle == num) {
                return true;
            } else if ((long) middle * middle > num) {
                right = middle - 1;
            } else {
                left = middle + 1;
            }
        }
        return false;
    }

    public boolean isPerfectSquare1(int num) {
        int left = 0, right = num / 2 + 1;
        while (left <= right) {
            int middle = left + (right - left) / 2;
            if ((long) middle * middle == num) {
                return true;
            } else if ((long) middle * middle < num) {
                left = middle + 1;
            }else{
                right = middle - 1;
            }
        }
        return false;
    }





    public static void main(String[] args) {

    }
}
